
package com.goseet.utils;

import android.content.*;
import android.util.Log;

import com.goseet.ffmpeg.*;

import java.io.File;
import java.io.IOException;

public final class i {
    private Context a;

    private ContentResolver b;

    public i(Context context) {
        a = context;
        ContentResolver contentresolver = context.getContentResolver();
        b = contentresolver;
        c.c();
    }

    /**
     * @param s source file to trim
     * @param j start time to trim (msec)
     * @param k end time to trim (msec)
     * @param flag whether overwrite
     * @return trimmed file name or null
     */
    public final String a(String s, int j, int k, boolean flag) {
        Object obj;
        a a1;
        File file2;
        d d1 = new d(s);
        obj = new b(); // MediaInput
        a1 = new a(); // MediaOutput
        String s1 = d1.getParentFile().getPath();
        File file = new File(s1);
        String s2 = d1.c();
        if (s2.length() < 3) {
            String s3 = String.valueOf(s2);
            s2 = (new StringBuilder(s3)).append("vidtrim").toString();
        }
        File file1;
        String s8;
        int l;
        try {
            String s4 = String.valueOf(s2);
            String s5 = (new StringBuilder(s4)).append("_").toString();
            StringBuilder stringbuilder = new StringBuilder(".");
            String s6 = d1.a();
            String s7 = stringbuilder.append(s6).toString();
            file1 = File.createTempFile(s5, s7, file);
        } catch (IOException ioexception) {
            int i1 = Log.v("VidTrim.MediaOperations", "Could not open temporary file!");
            boolean flag1 = a1.b();
            boolean flag2 = ((b) (obj)).b();
            obj = null;
            return null;
        }
        file2 = file1;
        if (!((b) (obj)).a(s)) {
            s8 = (new StringBuilder("MediaInput.open failed for file ")).append(s).toString();
            l = Log.v("VidTrim.MediaOperations", s8);
            obj = null;
            return ((String) (obj));
        }
        String s9 = file2.getPath();
        if (!a1.a(s9, ((b) (obj)))) {
            StringBuilder stringbuilder1 = new StringBuilder("MediaOutput.open failed for file ");
            String s10 = file2.getPath();
            String s11 = stringbuilder1.append(s10).toString();
            int j1 = Log.v("VidTrim.MediaOperations", s11);
            obj = null;
        } else {
            long l1 = j;
            long l2 = k;
            if (!((b) (obj)).a(a1, l1, l2)) {
                int k1 = Log.v("VidTrim.MediaOperations", "MediaInput.trim failed!");
                obj = null;
            } else if (!((b) (obj)).b()) {
                int i2 = Log.v("VidTrim.MediaOperations", "MediaInput.close failed!");
                obj = null;
            } else if (!a1.b()) {
                int j2 = Log.v("VidTrim.MediaOperations", "MediaOutput.close failed!");
                obj = null;
            } else {
                obj = file2.getPath();
                if (flag) {
                    ContentResolver contentresolver = b;
                    android.net.Uri uri = android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                    String as[] = new String[1];
                    as[0] = s;
                    int k2 = contentresolver.delete(uri, "_data=?", as);
                    File file3 = new File(s);
                    if (file2.renameTo(file3))
                        obj = s;
                }
            }
        }
        return ((String) (obj));
    }

    /**
     * @param s original file path and name with extension
     * @param s1 new file name without extension
     * @param l media id (_ID)
     * @return success or fail
     */
    public final boolean a(String s, String s1, long l) {
        boolean result;
        if (s1.trim().equals("")) {
            result = false;
        } else {
            d d1 = new d(s);
            String s2 = String.valueOf(d1.getParentFile().getPath());
            StringBuilder stringbuilder = (new StringBuilder(s2)).append("/").append(s1)
                    .append(".");
            String s3 = d1.a();
            String newFileName = stringbuilder.append(s3).toString();
            File file = new File(newFileName);
            if (file.exists()) {
                result = false;
            } else {
                if (!(new File(s)).renameTo(file)) {
                    result = false;
                } else {
                    ContentValues contentvalues = new ContentValues();
                    contentvalues.put("_data", newFileName);
                    ContentResolver contentresolver = b;
                    android.net.Uri uri = android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                    String s4 = (new StringBuilder("_ID=")).append(l).toString();
                    int j = contentresolver.update(uri, contentvalues, s4, null);
                    result = true;
                }
            }
        }
        return result;
    }
}
